#version 420

layout(lines_adjacency) in;
layout(line_strip,max_vertices = 2) out;

uniform mat4 ModelViewMatrix;
uniform mat4 NormalViewMatrix;
uniform mat4 ProjectionMatrix;
uniform mat4 ModelViewProjectionMatrix;
uniform vec3 VolumeSize;
uniform float LengthThreshold;

out vec3 pos;
out vec3 norm;
out vec3 texCoord;



void main()
{
    if(LengthThreshold > gl_in[1].gl_Position.w)
    {
        return;
    }

    for(int i = 0; i < 2; i++)
    {
        vec3 c0 = (ModelViewMatrix * vec4(gl_in[i].gl_Position.xyz, 1.0)).xyz;
        vec3 p  = (ModelViewMatrix * vec4(gl_in[i+1].gl_Position.xyz, 1.0)).xyz;
        vec3 c1 = (ModelViewMatrix * vec4(gl_in[i+2].gl_Position.xyz, 1.0)).xyz;

        vec3 v0 = p - c0;
        vec3 v1 = c1 - p;

        norm = normalize(cross(v1, v0));
        pos = p;
        texCoord = gl_in[i+1].gl_Position.xyz / VolumeSize;
        gl_Position = ProjectionMatrix * vec4(p, 1.0);
        EmitVertex();
    }

    EndPrimitive();
}


